//
//  SearchHistoryCell.m
//  WanCaiC8
//
//  Created by tangang on 2018/3/30.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "SearchHistoryCell.h"

@implementation SearchHistoryCell{
    UIImageView *headImage;
    QXLable     *labName;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        headImage=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"avatar"]];
        headImage.layer.masksToBounds=YES;
        headImage.layer.cornerRadius=20;
        [self.contentView addSubview:headImage];
        [headImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).with.offset(10);
            make.top.equalTo(self.contentView).with.offset(10);
            make.bottom.equalTo(self.contentView).with.offset(-10);
            make.size.mas_equalTo(CGSizeMake(40, 40));
        }];
        
        labName=[[QXLable alloc]init];
        //        labName.text=@"一只安静的哈士奇";
        labName.font=[UIFont systemFontOfSize:13];
        [self.contentView addSubview:labName];
        [labName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.left.equalTo(headImage.mas_right).with.offset(5);
            make.height.mas_equalTo(@30);
        }];
        
        UIButton *deleteBtn=[[UIButton alloc]init];
        [deleteBtn addTarget:self action:@selector(onclickDelete) forControlEvents:UIControlEventTouchUpInside];
        [deleteBtn setImage:[UIImage imageNamed:@"search_delete"] forState:UIControlStateNormal];
        [self.contentView addSubview:deleteBtn];
        [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.contentView).with.offset(-10);
            make.size.mas_equalTo(CGSizeMake(40, 30));
        }];
        
        UIView *line=[[UIView alloc]init];
        line.backgroundColor=DEFAULTBGCOLOR;
        [self.contentView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.contentView);
            make.height.mas_equalTo(@.7);
        }];
    }
    return self;
}

- (void)setModel:(ExpertsHotModel *)model{
    _model=model;
    labName.text=model.Name;
    [headImage sd_setImageWithURL:[NSURL URLWithString:model.Avater] placeholderImage:[UIImage imageNamed:@"avatar"]];
}


- (void)onclickDelete{
    if (self.deleteBlock) {
        self.deleteBlock(self.model);
    }
}

@end
